package com.xinsoft.controller.device;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.CusRepairApproveDTO;
import com.xinsoft.service.CusRepairApproveService;
import com.xinsoft.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cus/repairApprove")
public class CusRepairApproveController {

    @Autowired
    private CusRepairApproveService cusRepairApproveService;

    /**
     * 新增
     */
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> add(@RequestBody CusRepairApproveDTO cusRepairApproveDTO) {
        // 参数校验
        ValidatorUtils.validateEntity(cusRepairApproveDTO);
        return Response.succeed(cusRepairApproveService.addRepairApprove(cusRepairApproveDTO));
    }

    /**
     * 更新
     */
    @PostMapping("/edit")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> edit(@RequestBody  CusRepairApproveDTO cusRepairApproveDTO) {
        // 参数校验
        ValidatorUtils.validateEntity(cusRepairApproveDTO);
        return Response.succeed(cusRepairApproveService.editRepairApprove(cusRepairApproveDTO));
    }

    /**
     * 提交
     */
    @PostMapping("/submit")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> submit(@RequestBody  CusRepairApproveDTO cusRepairApproveDTO) {
        // 参数校验
        ValidatorUtils.validateEntity(cusRepairApproveDTO);
        cusRepairApproveService.submitRepairApprove(cusRepairApproveDTO);
        return Response.succeed();
    }

    /**
     * 获取详情
     */
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(cusRepairApproveService.getRepairApprove(id));
    }

    /**
     * 根据故障报修获取验收详情
     */
    @GetMapping("/getRepairApproveByBreakDownId")
    public Response<?> getRepairApproveByBreakDownId(@RequestParam(value = "breakDownId", defaultValue = "", required = true) Integer breakDownId) {
        return Response.succeed(cusRepairApproveService.getRepairApproveByBreakDownId(breakDownId));
    }
}
